package com.bdbit.ChargingStation.controller;

import com.bdbit.ChargingStation.services.MqttServerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MqttController {

    private final MqttServerService mqttServerService;

    public MqttController(MqttServerService mqttServerService) {
        this.mqttServerService = mqttServerService;
    }

    @PostMapping("/send-to-device")
    public String sendToDevice(
            @RequestParam String deviceId,
            @RequestParam String message) {

        // 调用修复后的方法（两个参数）
        mqttServerService.sendToDevice(deviceId, message);
        return "消息已发送到设备: " + deviceId;
    }
}